package com.ruoyi.project.shortUrl.util;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.project.system.role.domain.Role;
import com.ruoyi.project.system.role.service.RoleServiceImpl;

public class ShortUrlRoleKey {
	
	public static final String ADMIN = "admin";
	
	public static final String REGISTER = "register";
	
	public static final String NOT_REGISTER = "not_register";
	
	public static Role getRegisterRole() {
		RoleServiceImpl roleService = SpringUtils.getBean(RoleServiceImpl.class);
		Role filter = new Role();
		filter.setRoleKey(REGISTER);
		Role registerRole = roleService.selectRoleList(filter).stream().findFirst().orElse(null);
		
		if(registerRole==null) {
			Role role = new Role();
			role.setRoleName("注册用户");
			role.setRoleKey(REGISTER);
			role.setRoleSort("1");
			role.setStatus("0");
			role.setDataScope("1");
			role.setDelFlag("0");
			role.setCreateBy("admin");
			role.setCreateTime(DateUtils.getNowDate());
			roleService.insertRole(role);
			
			registerRole = role;
		}
		
		return registerRole;
	}
	
	public static Role getNotRegisterRole() {
		RoleServiceImpl roleService = SpringUtils.getBean(RoleServiceImpl.class);
		Role filter = new Role();
		filter.setRoleKey(NOT_REGISTER);
		Role registerRole = roleService.selectRoleList(filter).stream().findFirst().orElse(null);
		
		if(registerRole==null) {
			Role role = new Role();
			role.setRoleName("非注册用户");
			role.setRoleKey(NOT_REGISTER);
			role.setRoleSort("1");
			role.setStatus("0");
			role.setDataScope("1");
			role.setDelFlag("0");
			role.setCreateBy("admin");
			role.setCreateTime(DateUtils.getNowDate());
			roleService.insertRole(role);
			
			registerRole = role;
		}
		
		return registerRole;
	}
}
